/**
 ******************************************************************************
 * @file   drv_f4_Mpwm_Stimer.h
 * @brief  主定时器-PWM 从定时器-定时器
 * @author Moon
 * @version V1.0.0
 * @date 2022/09/12
 ******************************************************************************
 */
#ifndef _drv_F4_MPWM_STIMER_H
#define _drv_F4_MPWM_STIMER_H

#include "drv_include.h"

#define DRV_Mpwm_Ftimer_VERSION "V0.0.1"

/* private config -----------------------------------------------------------*/
typedef struct
{
	TIM_TypeDef *pwmx;
	uint16_t	p_index;
	TIM_TypeDef *timx;
	uint16_t	t_index;
} timer_private_t;

/* Public defines -----------------------------------------------------------*/
/* Public enum    -----------------------------------------------------------*/
typedef enum
{
	TIMER_CH1 = 0,
	TIMER_CH2,
	TIMER_CH3,
	TIMER_CH4
} TIMER_CHx_e;
/* Public Struct  -----------------------------------------------------------*/
typedef struct drv_mpwm_stimer drv_mpwm_stimer_t;
struct drv_mpwm_stimer
{
	/* ***************Public Parameter  *************** */
	const char	*PWM_DRV;
	const char	*TIMER_DRV;
	const char	*PIN_PWM;

	uint16_t 	pwm_Prescaler;		//PWM分频
	uint32_t 	pwm_freq; 			//pwm频率(Hz)
	float 		pwm_cmp;			//pwm占空比	(需小于1)
	TIMER_CHx_e pwm_chx;			//pwm输出通道
	uint32_t 	pwm_clock_freq;		//PWM定时器时钟频率

	uint32_t 	timer_pluse;		//从定时器上限值
	uint8_t 	PreempPriority;		//中断等级

	void (*TIMx_irq_CallBack)(void *);	//定时返回
	/* ***************Public Method     *************** */
	void (*TIMxCmd)(drv_mpwm_stimer_t *, uint8_t);	//使能/失能函数
	void (*TIMxITCmd)(drv_mpwm_stimer_t *, uint8_t);	//定时器中断使能函数
	void (*set_pwm_freq)							//参数设置
	(
		drv_mpwm_stimer_t *, 
		uint32_t freq, 				//pwm频率
		uint32_t timer_pluse		//从定时器上限值
	);
	/* ***************Private Attributes*************** */
	timer_private_t private;
};

/* Public Variable  ---------------------------------------------------------*/
// Pointer

// Array

// Const

/* Pubilc function prototypes -----------------------------------------------*/
int Drv_Mpwm_Stimer_Init(drv_mpwm_stimer_t *this);

#endif /*_drv_F4_MPWM_STIMER_H*/

/******************* (C) COPYRIGHT 2022 CIQTEK Moon *****END OF FILE****/
